import { EVector2, EVector3 } from "../../engine/Math";
import { config } from "../../cfw/config";
import { CoordinateType} from "../../cfw/tools/Define";
import MathHelper from "../../cfw/tools/MathHelper";
import { MoveToTarget } from "./MoveToTarget";


export class PlayerMoveAction extends MoveToTarget {
    private moveRatio: EVector2 = new EVector2();
    protected forward: EVector3 = new EVector3();
    protected right: EVector3 = new EVector3();
    protected dirVector: EVector3 = new EVector3();
    protected temp1: EVector3 = new EVector3()
    protected temp2: EVector3 = new EVector3()
    start(param: EVector2) {
        this.moveRatio.x = param.x;
        this.moveRatio.y = param.y;
    }
    updateH(time: number) {
        if (this.moveRatio.y == 0 && this.moveRatio.x == 0) {
            return;
        }
        MathHelper.multiplyNumberOut(this.self.forward, this.moveRatio.y, this.temp1)
        if (config.coordType == CoordinateType.RIGHT_HAND) {

            MathHelper.multiplyNumberOut(this.self.right, this.moveRatio.x, this.temp2)
        } else {
            MathHelper.multiplyNumberOut(this.self.right, -this.moveRatio.x, this.temp2)
        }
        EVector3.add(this.moveDirection, this.temp1, this.temp2)

        super.updateH(time);
        this.moveRatio.y = 0
        this.moveRatio.x = 0
    }
}